package
{
	import flash.events.Event;
	import flash.net.ObjectEncoding;
	
	import mx.controls.Alert;

	public class TesterRendererController
	{
		import mx.events.FlexEvent;
		public var id:uint;
		public var nc:NetConnection2 = new NetConnection2();
		public var ns:NetStream2;
		
		public  var objectEncoding:uint = ObjectEncoding.AMF0;
		public var serverUrl:String = "rtmp://localhost/live";
		public var streamName:String = "test";
		private var monitoringTime:uint = 1000;
		
		[Bindable]
		public var volume:uint = 100;		
		
		[Bindable]
		public var bufor:Number = 0;		
		
		public function creationCompleteHandler(event:FlexEvent):void
		{
			nc.encoding = objectEncoding;
			nc.url = serverUrl;
			nc.dispatcher.addEventListener(NetConnection2.CONNECTED_EVENT, connectedHandler);
			nc.dispatcher.addEventListener(NetConnection2.DISCONNECTED_EVENT, disconnectedHandler);
			nc.dispatcher.addEventListener(NetConnection2.UNKNOWN_EVENT, disconnectedHandler);
			
			// connect command
			nc.connect();
			
			ns = new NetStream2(nc, monitoringTime);			
		}

		public function setBufor(x:Number):void {
			bufor = x;
			ns.setBufor(x);
		}
		
		
		public function setVolume(x:int):void {
			volume = x;
			ns.setVolume(x);
		}
		
		private function connectedHandler(e:Event):void {
			ns.play(streamName);	
			trace(this + ": connected");
		}
		
		private function disconnectedHandler(e:Event):void {
			trace(this.toString() + ": disconnected");
		}
		
		public function toString():String {
			return "TesterRendererController:" + id +":"; 
		}
	}
}